package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import servic.impl.CustomerManagerFactory;
import service.CustomerManager;

public class ShowHobbyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerManager manager;
       
    public ShowHobbyServlet() {
        super();
        manager=CustomerManagerFactory.getInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		System.out.println(id);
		
		int user_id=Integer.parseInt(id);
		String[] hobby = manager.getCustomerHobby(user_id);
		int length = hobby.length;
		String[] act_hobby = new String[length];
		for(int i=0;i<length; i++){
			switch (hobby[i]) {
			case "1":
				act_hobby[i]="basketball";
				break;
			case "2":
				act_hobby[i]="football";
				break;
			case "3":
				act_hobby[i]="table tennis";
				break;
			case "4":
				act_hobby[i]="running";
				break;
			case "5":
				act_hobby[i]="music";
				break;
			case "6":
				act_hobby[i]="reading";
				break;
			default:
				break;
			}
		}
		
		request.setAttribute("hobby", act_hobby);
		request.getRequestDispatcher("showHobby.jsp").forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
